﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBS.Bll;
using IBS.Model;
namespace Testing
{
    class Program
    {
        static void Main(string[] args)
        {
            var container = new IbsContainer();

            string fromCardNumber = null;
            string toCardNumber = null;
            int amount = 0;
            int requestCount = 0;
            int sleep = 0;
            string ISO = null;
            Card card = null;
            string cardOwner = null;
            //while (true)
            //{
            //    try
            //    {
            //        Console.WriteLine("Enter please cardNumber from:");
            //        fromCardNumber = Console.ReadLine();
            //        card = container.CardService.GetCardByNumber(fromCardNumber);
            //        Console.WriteLine(card.Account.Currency.ISO);
            //        cardOwner = container.AuthorityService.GetClentUserName(card.Client);
            //        break;
            //    }
            //    catch (BusinessException b)
            //    {
            //        Console.WriteLine(b.Message);
            //    }
            //}

            //while (true)
            //{
            //    try
            //    {
            //        Console.WriteLine("Enter please cardNumber to:");
            //        toCardNumber = Console.ReadLine();
            //        card = container.CardService.GetCardByNumber(toCardNumber);
            //        Console.WriteLine(card.Account.Currency.ISO);
            //        break;
            //    }
            //    catch (BusinessException b)
            //    {
            //        Console.WriteLine(b.Message);
            //    }
            //}

        
            // ConsoleKeyInfo ch; 
 
            //Console.WriteLine("Enter please ISO. (Press b for BYR and u for USD):");
            //do 
            //{
            //        ch = Console.ReadKey(true);
            //       if (ch.KeyChar == 'u' || ch.KeyChar == 'U' )
            //           ISO = "USD";
            //    if (ch.KeyChar == 'b' || ch.KeyChar == 'B')
            //        ISO = "BYR";

            // } while (ISO == null);
           

            //Console.WriteLine("Enter please amount count (1 - 10k):");
            //while (true)
            //{
            //    try
            //    {
            //        amount = Int32.Parse(Console.ReadLine());
            //        if (amount < 1 || amount > 10000)
            //            throw new Exception();
            //        break;
            //    }
            //    catch (Exception)
            //    {
            //        Console.WriteLine("Amount must be value between 1 and 10k");
            //    }
            //}

            //Console.WriteLine("Enter please requests count (1 - 10k):");
            //while (true)
            //{
            //    try
            //    {
            //        requestCount = Int32.Parse(Console.ReadLine());
            //        if (requestCount < 1 || requestCount > 10000)
            //            throw new Exception();
            //        break;
            //    }
            //    catch (Exception)
            //    {
            //        Console.WriteLine("Requests count must be value between 1 and 10k");
            //    }
            //}


            //Console.WriteLine("Enter please pause between two requests (Milliseconds):");
            //while (true)
            //{
            //    try
            //    {
            //        sleep = Int32.Parse(Console.ReadLine());
            //        if (requestCount < 1 || requestCount > 10000)
            //            throw new Exception();
            //        break;
            //    }
            //    catch (Exception)
            //    {
            //        Console.WriteLine("Pause between two requests count must be value between 1 and 10k");
            //    }
            //}
            fromCardNumber = "5548557458764557";
            toCardNumber = "45485538854026510";
            ISO="USD";
            requestCount =1000;
            sleep = 100;
            amount = 2;
            card = container.CardService.GetCardByNumber(fromCardNumber);
            cardOwner = container.AuthorityService.GetClentUserName(card.Client);
            Console.Clear();
            Console.WriteLine("From {0} To {1} \n {2} {5} amount per request \n {3} requests with {4} milliseconds pause",
                fromCardNumber, toCardNumber, amount, requestCount, sleep, ISO);
            
            try
            {
                for (var i = 0; i < requestCount; i++)
                {
                    Console.WriteLine("Request {0} ...", i);
                    container.CardService.TransferToCard(fromCardNumber, toCardNumber, amount, ISO, cardOwner);
                }
            }
            catch (BusinessException b)
            {
                Console.WriteLine(b.Message);
            }
            Console.ReadLine();
        }
    }
}
